package com.lipaluma.field.mapper.single.impl;
import java.lang.reflect.Field;
import java.math.BigDecimal;

import com.lipaluma.context.Context;
import com.lipaluma.exceptions.CsvParserProcessException;
import com.lipaluma.field.mapper.mapping.MappingInfo;
import com.lipaluma.field.mapper.mapping.MappingOptions;
import com.lipaluma.field.mapper.single.AbstractStandardSingleFieldMapper;
import com.lipaluma.field.validator.ChainValidator;
import com.lipaluma.xml.mapping.XmlFieldMapping;

/**
 * MapColumn allows primitives numerics values
 * 
 * @author Mario
 */
public class BigDecimalFieldMapper extends AbstractStandardSingleFieldMapper {

	public BigDecimalFieldMapper() {}
	/**
	 * Field Mapper that parses a BigDecimal
	 * @param mapping information of mapping
	 */
	public BigDecimalFieldMapper(MappingInfo mapping) {
		super(mapping);
	}

	@Override
	protected void init(MappingOptions mappingOptions) {

	}
	
	public ChainValidator createChainValidator(Context context, Field field) {
		//TODO : à faire
		return null;
	}

	public ChainValidator createChainValidator(Context context, Field field, XmlFieldMapping mapping) {
		//TODO : à faire
		return null;
	}

	@Override
	protected Object parseExtractedValue(String value) {
		try {
			return new BigDecimal(value);
		} catch (NumberFormatException e) {
			throw new CsvParserProcessException(this, "value "+value+" cannot be parsed to a BigDecimal", e);
		}
	}
	
	@Override
	protected Object formatValueToWriteOnRow(Object value) {
		return value.toString();
	}
}
